<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
	</head>
	<body>
		<div id="app">
			<h1>{{title}}</h1>
			<div v-if="!isLogin">用户名:<input type="text" v-model="username" /></div>
			<div v-if="!isLogin">密码:<input type="password" v-model="password"/></div>
			<div>
				<button v-show="!isLogin" type="button" @click="login()">登陆</button>
				<button v-show="isLogin"  type="button" @click="logout()">登出</button>
			</div>
		</div>

		<script>
			const vm = Vue.createApp({
				data() {
					return {
						title:"用户登录",
						isLogin: false,
						username:"",
						password:"",
					}
				},
				methods:{
					logout:function()
					{
						this.isLogin = false;
						this.title = "用户登录";
					},
					login()
					{
						if(this.username.length>0&& this.password.length>0)
						{
							this.isLogin = true;
							this.title = this.username + ",欢迎光临!"
						}
						else
						{
							alert("请输入用户名密码");
						}
					}
				}
			})
			vm.mount("#app");
		</script>
	</body>
</html>
